package com.dd.ljzapplication.activity;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;

import com.dd.ljzapplication.R;
import com.dd.ljzapplication.adapter.LogAdapter;
import com.dd.ljzapplication.bean.EnumSpotCheckInfo;
import com.dd.ljzapplication.bean.RefreshLoan;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import base.BaseUtilActivity;

/**
 * Created by LiJZ on 2016/11/11.
 * e实贷日志，eventbus相关
 */

public class LogActivity extends BaseUtilActivity {

	private static final String TAG = "####";
	private RecyclerView mRecyclerView;
	private LogAdapter mAdapter;
	private Button mBtn;

	@Override
	protected int setLayoutID() {
		return R.layout.activity_log;
	}

	@Override
	protected void init() {

	}

	@Override
	protected void initActionBar() {

	}

	@Override
	protected void initView() {
		mBtn = (Button) findViewById(R.id.btn);
		mRecyclerView = (RecyclerView) findViewById(R.id.rv);
		LinearLayoutManager layout = new LinearLayoutManager(this);
		mAdapter = new LogAdapter(this, true);

		RadioButton rb = (RadioButton) findViewById(R.id.rb);
		RadioButton rb1 = (RadioButton) findViewById(R.id.rb1);

		rb.setClickable(false);
		rb1.setClickable(false);
		rb.setChecked(true);
		layout.setOrientation(LinearLayoutManager.VERTICAL);
		mRecyclerView.setLayoutManager(layout);
		mRecyclerView.setAdapter(mAdapter);
		ArrayList<EnumSpotCheckInfo.SpotChecksBean> beans = new ArrayList<>();
		EnumSpotCheckInfo.SpotChecksBean bean;
		for (int i = 0; i < 50; i++) {
			bean = new EnumSpotCheckInfo.SpotChecksBean();
			bean.setContent("this is content-----" + i);
			bean.setType(1);
			bean.setContentID("contentID:" + i);
			if (i % 7 == 0) {
				bean.setType(0);
			}
			beans.add(bean);
		}
		mAdapter.setListData(beans);

	}

	@Override
	protected void initEvent() {
		mBtn.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				Log.i("####", "onClick: " + mAdapter.getResult());
				HashMap<String, Integer> result = mAdapter.getResult();
				Log.i("####", "------------------top------------------");
				for (Map.Entry<String, Integer> entry : result.entrySet()) {
					Log.i(TAG, "key:" + entry.getKey() + "------" + "value:" + entry.getValue());
				}
				Log.i("####", "------------------end------------------");
				EventBus.getDefault().post(new RefreshLoan());
			}
		});
	}
}
